{ include file="../Common/head_authority.html" }
<body>
<div class="container-fluid">
    <div class="row" style="margin: 20px 0px;">
        <b>编辑用户</b>
        <a href="javascript:history.back();" style="float: right;">返回</a>
    </div>
    <form action="#" method="post">
        <div class="row" style="height: 35px;line-height: 35px;margin-top: 15px;">
            <div class="col-sm-2 col-md-2 col-lg-2" style="text-align: right">
                <b>昵称</b>
            </div>
            <div class="col-sm-5 col-md-5 col-lg-5">
                <input type="text" name="username" id="username" class="form-control" value="{ $oldData.username }"/>
            </div>
            <div class="col-sm-5 col-md-5 col-lg-5" style="display: none" id="username_w">
                <p style="color: red;font-size: 12px;">
                    <span class="glyphicon glyphicon-exclamation-sign"></span>
                    &nbsp;昵称已存在，请重新设置！
                </p>
            </div>
            <div class="col-sm-5 col-md-5 col-lg-5" style="display: none" id="username_r">
                <p style="color: lawngreen;font-size: 12px;">
                    <span class="glyphicon glyphicon-ok"></span>
                    &nbsp;昵称设置正确！
                </p>
            </div>
        </div>
        <div class="row" style="height: 35px;line-height: 35px;margin-top: 15px;">
            <div class="col-sm-2 col-md-2 col-lg-2" style="text-align: right">
                <b>邮箱</b>
            </div>
            <div class="col-sm-5 col-md-5 col-lg-5">
                <input type="text" name="email" id="email" class="form-control" value="{ $oldData.email }"/>
            </div>
            <div class="col-sm-5 col-md-5 col-lg-5" style="display: none" id="email_w">
                <p style="color: red;font-size: 12px;">
                    <span class="glyphicon glyphicon-exclamation-sign"></span>
                    &nbsp;请输入正确的邮箱！
                </p>
            </div>
            <div class="col-sm-5 col-md-5 col-lg-5" style="display: none" id="email_r">
                <p style="color: lawngreen;font-size: 12px;">
                    <span class="glyphicon glyphicon-ok"></span>
                    &nbsp;邮箱格式正确！
                </p>
            </div>
        </div>
        <input type="hidden" id="uid" value="{$oldData.id}">
        <div class="row" style="height: 35px;line-height: 35px;margin-top: 15px;">
            <div class="col-sm-2 col-md-2 col-lg-2" style="text-align: right">
                <b>所属角色</b>
            </div>
            <div class="col-sm-5 col-md-5 col-lg-5">
                {foreach from="$roleData" item="v"}
                    {if in_array($v.id,$rid)}
                    <span style="margin-right: 15px">
                       <input checked type="checkbox" name="rid[]" value="{$v.id}" style="display: inline-block;vertical-align: middle;margin-bottom: 5px;"/>{$v.name}
                    </span><br/>
                    {else}
                    <span style="margin-right: 15px">
                       <input type="checkbox" name="rid[]" value="{$v.id}" style="display: inline-block;vertical-align: middle;margin-bottom: 5px;"/>{$v.name}
                    </span><br/>
                    {/if}
                {/foreach}
            </div>
        </div>
        <div class="row" style="height: 35px;line-height: 35px;margin-top: 15px;">
            <div class="col-sm-2 col-md-2 col-lg-2" style="text-align: right">
            </div>
            <div class="col-sm-5 col-md-5 col-lg-5">
                <button type="submit" id="sub" class="btn btn-primary pull-right">保存</button>
            </div>
        </div>
    </form>

    {literal}
    <script>
        $(document).ready(function(){
            $("#username").blur(function(){
                var username = $("#username").val();
                var uid = $("#uid").val();
                $.ajax({
                    type:"post",
                    url:"./admin.php?c=Authority&m=checkEditUserName",
                    data:{username:username,uid:uid},
                    dataType:"json",
                    success:function(data){
                        if(data){
                            $("#username_r").css('display','block');
                            $("#username_w").css('display','none');
                            $("#sub").removeAttr("disabled");
                        }else{
                            $("#username_w").css('display','block');
                            $("#username_r").css('display','none');
                            $("#sub").attr("disabled","disabled");
                        }
                    }
                })
            })
            $("#email").blur(function(){
                var isEmail = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
                var email = $("#email").val();
                if(isEmail.test(email)){
                    $("#email_r").css('display','block');
                    $("#email_w").css('display','none');
                    $("#sub").removeAttr("disabled");
                }else{
                    $("#email_w").css('display','block');
                    $("#email_r").css('display','none');
                    $("#sub").attr("disabled","disabled");
                }
            })
            $("#pwd").blur(function(){
                var password = $("#password").val();
                var pwd = $("#pwd").val();
                if(password == pwd){
                    $("#pwd_r").css('display','block');
                    $("#pwd_w").css('display','none');
                    $("#sub").removeAttr("disabled");
                }else{
                    $("#pwd_w").css('display','block');
                    $("#pwd_r").css('display','none');
                    $("#sub").attr("disabled","disabled");
                }
            })
            $("#password").blur(function(){
                var password = $("#password").val();
                if(password.length < 6){
                    $("#password_w").css('display','block');
                    $("#password_r").css('display','none');
                    $("#sub").attr("disabled","disabled");
                }else{
                    $("#password_r").css('display','block');
                    $("#password_w").css('display','none');
                    $("#sub").removeAttr("disabled");
                }
            })
        })
    </script>
    {/literal}
</body>
</html>